home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / envman.lha / EnvManager / enventry.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-13  |  2.2 KB  |  116 lines

  1. // $Id$
  2. #include <exec/types.h>
  3. #include <proto/exec.h>
  4. #include <string.h>
  5. #include <mydebug.h>
  6.  
  7. #include "envdef.h"
  8. #include "enventry.h"
  9.  
  10. IMPORT nlist *envarclist ;
  11. IMPORT nlist *envlist ;
  12. IMPORT nlist *envloclist ;
  13.  
  14. enventry *findname(nlist *l, STRPTR name)
  15. {
  16. enventry *c = (enventry *)l->first() ;
  17.  
  18.     while (c && stricmp(c->name, name))
  19.         c = (enventry *)c->next() ;
  20.     return c ;
  21. }
  22.  
  23. enventry *findvar(STRPTR name)
  24. {
  25. enventry    *ev = NULL ;
  26.  
  27.     if (ev = findname(envlist, name))
  28.         return ev ;
  29.     if (ev = findname(envloclist, name))
  30.         return ev ;
  31.     ev = findname(envarclist, name) ;
  32.         return ev ;
  33. }
  34.  
  35.  
  36. enventry::enventry(STRPTR n, STRPTR c, long s, char t)
  37. {
  38.     size = s ;
  39.     name = new char[strlen(n)+1] ;
  40.     strcpy(name, n) ;
  41.     label = entry ;
  42.     contents = new char[size+1] ;
  43.     CopyMem(c, contents, size) ;
  44.     contents[size] = '\0' ;
  45.     type = t ;
  46.     setentry() ;
  47. }
  48.  
  49.  
  50. void enventry::setentry()
  51. {
  52. int i ;
  53.  
  54.     binary = FALSE ;
  55.     notnullterm = FALSE ;
  56.     for (i=0; i<size && !binary; i++) {
  57.         binary =  ((UBYTE(contents[i]) < ' ') && (contents[i] != 0x0A)) || ((contents[i] == 0x0A) && (i<(size-1))) ;
  58.     }
  59.  
  60.     if (binary) {
  61.         for (i=0; i<size && !notnullterm ; i++) {
  62.             notnullterm = BOOL(contents[i] == 0x00) ;
  63.         }
  64.     }
  65.     else
  66.         notnullterm = FALSE ;
  67.     info =  BOOL((strlen(name) > 4) && (!strcmp(&name[strlen(name)-5], ".info"))) ;
  68.     strncpy(entry, name, MAXNAME) ;
  69.     entry[MAXNAME] = '\0' ;
  70.     strcat(entry, " ") ;
  71.     while(strlen(entry) < MAXNAME)
  72.         strcat(entry, " ") ;
  73.     if (type == ALIAS_TYPE) {
  74.         strcat(entry, "[ALIAS] ") ;
  75.     }
  76.     strncat(entry, contents, MAXCONTENTS) ;
  77. }
  78.  
  79. enventry::~enventry()
  80. {
  81.     delete name ;
  82.     delete contents ;
  83. }
  84.  
  85. BOOL enventry::islocale()
  86. {
  87.     return (type == LOCAL_TYPE) ;
  88. }
  89. BOOL enventry::isalias()
  90. {
  91.     return (type == ALIAS_TYPE) ;
  92. }
  93. BOOL enventry::isglobal()
  94. {
  95.     return findname(envlist, name) != NULL ;
  96. }
  97.  
  98. BOOL enventry::isarchived()
  99. {
  100.     return findname(envarclist, name) != NULL ;
  101. }
  102.  
  103. BOOL enventry::isbinary()
  104. {
  105.     return binary ;
  106. }
  107.  
  108. BOOL enventry:: isnullterm()
  109. {
  110.     return !notnullterm ;
  111. }
  112.  
  113. BOOL enventry::isinfo()
  114. {
  115.     return info ;
  116. }